package ipsite.data;

public class Memcache {
	public static void setMemcache(String key,String domain)
	{
		try {
			Object obj = MyCache.getInstance().get(key);
			
			if(obj==null)
			{
				String strDomain = domain;
				MyCache.getInstance().set(key,3600*24,strDomain);				
			}
			else
			{
				String[] arrDomain = obj.toString().split(",");
				String strDomain = "";
				int j = 0;
				for (int i = 0; i < arrDomain.length; i++) {
					if(domain.equals(arrDomain[i]))
						j=1;
				}
				if(j==0)
				{
					if(arrDomain.length>18)
					{ 
						for (int i = 0; i < arrDomain.length; i++) {
							if(i!=0)
								strDomain += arrDomain[i]+",";
						}
						strDomain += domain;
					} else {
						strDomain = obj.toString()+","+domain;
					}
				} else {
					for (int i = 0; i < arrDomain.length; i++) {
						strDomain += arrDomain[i]+",";
					}
					strDomain = strDomain.replaceAll("[,]$", "");
				}
				MyCache.getInstance().set(key,3600*24,strDomain);

			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	public static String[] getMemcache(String key)
	{
		String[] arrDomain = null;
		Object obj = null;
		try{
			obj = MyCache.getInstance().get(key);
		} catch (Exception e)
		{
			
		}
		if(obj != null)
		{
			arrDomain = obj.toString().split(",");
		}
		return arrDomain;
	}
}
